package com.ruoyi.controller.purchase;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.purchase.MesPurchaseReceiptItem;
import com.ruoyi.service.purchase.IMesPurchaseReceiptItemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购入库明细Controller
 * 
 * @author ruoyi
 * @date 2024-01-01
 */
@RestController
@RequestMapping("/purchase/receiptItem")
public class MesPurchaseReceiptItemController extends BaseController
{
    @Autowired
    private IMesPurchaseReceiptItemService mesPurchaseReceiptItemService;

    /**
     * 查询采购入库明细列表
     */
    @PreAuthorize("@ss.hasPermi('purchase:receiptItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(MesPurchaseReceiptItem mesPurchaseReceiptItem)
    {
        startPage();
        List<MesPurchaseReceiptItem> list = mesPurchaseReceiptItemService.selectMesPurchaseReceiptItemList(mesPurchaseReceiptItem);
        return getDataTable(list);
    }

    /**
     * 根据入库单ID查询明细列表
     */
    @PreAuthorize("@ss.hasPermi('purchase:receiptItem:list')")
    @GetMapping("/receipt/{receiptId}")
    public AjaxResult getItemListByReceiptId(@PathVariable Long receiptId)
    {
        List<MesPurchaseReceiptItem> list = mesPurchaseReceiptItemService.selectItemListByReceiptId(receiptId);
        return success(list);
    }

    /**
     * 根据物料编码查询入库明细
     */
    @PreAuthorize("@ss.hasPermi('purchase:receiptItem:list')")
    @GetMapping("/material/{materialCode}")
    public AjaxResult getItemListByMaterialCode(@PathVariable String materialCode)
    {
        List<MesPurchaseReceiptItem> list = mesPurchaseReceiptItemService.selectItemListByMaterialCode(materialCode);
        return success(list);
    }

    /**
     * 根据批次号查询入库明细
     */
    @PreAuthorize("@ss.hasPermi('purchase:receiptItem:list')")
    @GetMapping("/batch/{batchCode}")
    public AjaxResult getItemListByBatchCode(@PathVariable String batchCode)
    {
        List<MesPurchaseReceiptItem> list = mesPurchaseReceiptItemService.selectItemListByBatchCode(batchCode);
        return success(list);
    }

    /**
     * 导出采购入库明细列表
     */
    @PreAuthorize("@ss.hasPermi('purchase:receiptItem:export')")
    @Log(title = "采购入库明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesPurchaseReceiptItem mesPurchaseReceiptItem)
    {
        List<MesPurchaseReceiptItem> list = mesPurchaseReceiptItemService.selectMesPurchaseReceiptItemList(mesPurchaseReceiptItem);
        ExcelUtil<MesPurchaseReceiptItem> util = new ExcelUtil<MesPurchaseReceiptItem>(MesPurchaseReceiptItem.class);
        util.exportExcel(response, list, "采购入库明细数据");
    }

    /**
     * 获取采购入库明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('purchase:receiptItem:query')")
    @GetMapping(value = "/{itemId}")
    public AjaxResult getInfo(@PathVariable("itemId") Long itemId)
    {
        return success(mesPurchaseReceiptItemService.selectMesPurchaseReceiptItemByItemId(itemId));
    }

    /**
     * 新增采购入库明细
     */
    @PreAuthorize("@ss.hasPermi('purchase:receiptItem:add')")
    @Log(title = "采购入库明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesPurchaseReceiptItem mesPurchaseReceiptItem)
    {
        return toAjax(mesPurchaseReceiptItemService.insertMesPurchaseReceiptItem(mesPurchaseReceiptItem));
    }

    /**
     * 修改采购入库明细
     */
    @PreAuthorize("@ss.hasPermi('purchase:receiptItem:edit')")
    @Log(title = "采购入库明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesPurchaseReceiptItem mesPurchaseReceiptItem)
    {
        return toAjax(mesPurchaseReceiptItemService.updateMesPurchaseReceiptItem(mesPurchaseReceiptItem));
    }

    /**
     * 删除采购入库明细
     */
    @PreAuthorize("@ss.hasPermi('purchase:receiptItem:remove')")
    @Log(title = "采购入库明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{itemIds}")
    public AjaxResult remove(@PathVariable Long[] itemIds)
    {
        return toAjax(mesPurchaseReceiptItemService.deleteMesPurchaseReceiptItemByItemIds(itemIds));
    }
}